//
import com.alpha.util.SiblingIterator;
import java.util.*;
import java.util.Iterator;
import org.htmlparser.*;
import org.htmlparser.filters.*;
import org.htmlparser.tags.*;
import org.htmlparser.tags.CompositeTag;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.util.*;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author alvar
 */
public class mytest3 {
    public static void main(String a[]) throws Exception{
        String url = "http://www.discuss.com.hk/archiver/";
        Parser p = new Parser(url);
        NodeList list = p.parse(new TagNameFilter("li"));
        List<Node> nodelist= new ArrayList<Node>();
        Node sample = null;
        for(Node n:list.toNodeArray()){
            if(!(n.getChildren().extractAllNodesThatMatch(new TagNameFilter("h3")).toHtml().trim().equals(""))){
                sample = n;
                break;
            }   
            if(!(n.getChildren().extractAllNodesThatMatch(new TagNameFilter("h3")).toHtml().trim().equals(""))){
                
//                System.out.println(n.getChildren().toHtml()+"\n\n");
//                System.out.println(n.toHtml()+"\n\n");
//                nodelist.add(n);
            }                                                       
        }
//        System.out.println(sample.toHtml()+"\n\n\n\n");
        SimpleNodeIterator i = ((CompositeTag)sample.getChildren().elementAt(1)).elements();
        System.out.println(((CompositeTag)sample.getChildren().elementAt(1)).getChildrenAsNodeArray().length);
        while(i.hasMoreNodes()){
            Node h = i.nextNode();
            if(h instanceof Bullet && h instanceof CompositeTag){
                System.out.println(h.getChildren().size());
                for(Node k:h.getChildren().toNodeArray()){
                    if (k instanceof LinkTag){
                        System.out.println(k.toHtml()+"->link");
                    }
                    if(k instanceof BulletList){
                        System.out.println(k.toHtml()+"-> blist");
                    }
//                    System.out.println("this is child");
//                    System.out.println(k.toHtml());
                }
                System.out.println("=============");
//                System.out.print(((CompositeTag) h).getChildren().toHtml()+"\n--------------\n\n");
                
            }
            
        }
            
            
    }
}
